#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=3e5+3,INF=1e9;
int n,lim,rt,A,B,tim,st[N],ed[N],id[N],fa[N],sta[N],len[N],dep[N],to[N],k1[N],k2[N];
bool f[N],g[N],h[N];
vector<int>ve[N],res[N],now[N];
void Init(int x)
{
	dep[x]=dep[fa[x]]+1;sta[dep[x]]=x;st[x]=++tim;
	if(dep[x]>A)res[sta[dep[x]-A]].push_back(x),to[x]=sta[dep[x]-A+1];
	if(dep[x]>B)now[sta[dep[x]-B]].push_back(x);
	for(int y:ve[x])if(y!=fa[x])fa[y]=x,Init(y);
	ed[x]=tim;
}
struct BIT
{
	int tr[N];
	void Clear(){for(int i=0;i<=n;i++)tr[i]=0;}
	void Add(int x,int y){for(;x<=n;x+=x&-x)tr[x]+=y;}
	void Upd(int l,int r,int d){Add(l,d),Add(r+1,-d);}
	int Ask(int x){int s=0;for(;x;x-=x&-x)s+=tr[x];return s;}
}T1;
struct ZKW
{
	int DT=(1<<19),tr[1<<20|3];
	void Clear(){for(int i=0;i<2*DT;i++)tr[i]=INF;}
	void Upd(int l,int r,int d)
	{
		if(l>r)return;
		for(l+=DT-1,r+=DT+1;l+1!=r;l>>=1,r>>=1)
		{
			if(~l&1)tr[l+1]=min(tr[l+1],d);
			if(r&1)tr[r-1]=min(tr[r-1],d);
		}
		//cout<<"Upd: "<<L<<" "<<R<<" "<<d<<endl;
		//for(int i=l;i<=r;i++)tr[i]=min(tr[i],d);
	}
	int Ask(int p)
	{
		//return tr[p];
		p+=DT;int s=tr[p];
		while(p>1)s=min(s,tr[p>>=1]);
		return s;
	}
}T2;
void Get(int x)
{
	//cout<<"Get: "<<x<<" "<<res[x].size()<<endl;
	if(!res[x].size())
	{
		if(x<=lim)return;
		int s1=0,s2=0;
		for(int y:ve[x])if(len[y]<=B)!s1?s1=s2=y:s2=y;
		//cout<<s1<<" "<<s2<<" "<<len[9]<<endl;
		if(!s1)
		{
			f[x]=1;
			for(int y:ve[x])h[y]=1;
			return;
		}
		if(s1==s2)h[s1]=1;
		return;
	}
	if(to[res[x][0]]==to[res[x].back()])
	{
		int son=to[res[x][0]];
		for(int id:res[x])if(!g[id])f[x]=1;
		for(int y:ve[x])if(y!=son)h[y]=f[x];
		h[son]=x>lim;
		for(int y:ve[x])if(y!=son&&len[y]<=B)h[son]=0;
		return;
	}
	int s1=0,s2=0;
	for(int id:res[x])if(!g[id])!s1?s1=s2=to[id]:s2=to[id];
	if(!s1)return;
	f[x]=1;
	for(int y:ve[x])if(y!=s1||y!=s2)h[y]=1;
}
void Len(int x)
{
	len[x]=x<=lim?1:INF;
	for(int y:ve[x])Len(y),len[x]=min(len[x],len[y]+1);
}
bool Find(int x,int Fa,int z,int w)
{
	bool s=0;
	if(!w)s=(f[x]==0);
	if(z==B)return s;
	if(w)s|=Find(fa[x],x,z+1,1);
	for(int y:ve[x])if(y!=Fa)s|=Find(y,x,z+1,0);
	return s;
}
void Upd(int x)
{
	//cout<<"Upd: "<<x<<" "<<f[x]<<endl;
	for(int y:ve[x])if(!h[y])T1.Upd(st[y],ed[y],1);
	int s1=INF,s2=INF,v1=0,v2=0;
	k1[x]=k2[x]=INF;
	for(int y:ve[x])
	{
		if(k1[y]<s1)s2=s1,s1=k1[y],v2=v1,v1=y;
		else if(k1[y]<s2)s2=k1[y],v2=y;
	}
	if(v2)
	{
		T2.Upd(st[v1],ed[v1],s2-2*dep[x]);
		T2.Upd(st[x]+1,st[v1]-1,s1-2*dep[x]);
		T2.Upd(ed[v1]+1,ed[x],s1-2*dep[x]); 
	}
	else if(v1)T2.Upd(st[x]+1,ed[x],s1-2*dep[x]);
	if(f[x]==0)
	{
		if(dep[x]<s1)s2=s1,s1=dep[x];
		else if(dep[x]<s2)s2=dep[x];
	}
	k1[x]=s1;k2[x]=s2;
}
int Mn(int x)
{
	if(f[x]==0)return dep[x]; 
	int s=INF;
	for(int y:ve[x])s=min(s,Mn(y));
	return s;
}
bool Chk()
{
	for(int i=1;i<=n;i++)f[i]=g[i]=h[i]=0;
	Len(rt);T1.Clear();T2.Clear();
	for(int t=1;t<=n;t++)
	{
		int x=id[t];Get(x);Upd(x);
		//cout<<"F: "<<x<<" "<<f[x]<<endl;
		//for(int y:ve[x])cout<<"H: "<<y<<" "<<h[y]<<endl;
		for(int y:now[x])
		{
			g[y]|=f[y]==0;
			g[y]|=(T1.Ask(st[y])>T1.Ask(st[x]));
			g[y]|=Find(y,0,0,1);
			//int o=Find(y,0,0,1);
			//int pp=k1[y]-dep[y]<=B|dep[y]+T2.Ask(st[y])<=B;
			//assert(o==pp);
			//g[y]=o; 
			//g[y]|=k1[y]-dep[y]<=B;
			//g[y]|=dep[y]+T2.Ask(st[y])<=B;
			//cout<<Find(y,0,0,1)<<endl;
			//cout<<k1[y]-dep[y]<<" "<<dep[y]+T2.Ask(st[y])<<" "<<B<<endl;
			//g[y]|=Find(y,0,0,1);
			//g[y]|=k1[y]-dep[y]<=B;
			//g[y]|=dep[y]+T2.Ask(st[y])<=B; 
		}
		//for(int y:now[x])cout<<"G: "<<y<<" "<<g[y]<<endl;
	}
	return f[rt];
}
int main()
{
	freopen("nim.in","r",stdin);
	freopen("nim.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>rt>>A>>B;
	if(A<=B){cout<<1;return 0;}
	for(int i=1,x,y;i<n;i++)cin>>x>>y,ve[x].push_back(y),ve[y].push_back(x);
	Init(rt);iota(id+1,id+n+1,1);
	sort(id+1,id+n+1,[](int X,int Y){return dep[X]>dep[Y];});
	for(int i=1;i<=n;i++)for(int j=0;j<(int)ve[i].size();j++)if(ve[i][j]==fa[i])
		{ve[i].erase(ve[i].begin()+j);break;}
	//lim=60;cout<<Chk();exit(0);
	ll l=1,r=n,s=0;
	while(l<=r)lim=(l+r)/2,!Chk()?(s=lim,r=lim-1):l=lim+1;
	cout<<s;
}
